package utils;

import entidades.usuarios.Usuario;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class PreferencesHelper
{
	public static final String ID = "id";
	public static final String RECORDAR = "recordar";
	public static final String GCM = "gcm_usuario";
	
	public static final String USUARIO = "usuario";
	public static final String CLAVE = "clave";
	
	private SharedPreferences preferences;
	
	public PreferencesHelper (Context context)
	{
		preferences = PreferenceManager.getDefaultSharedPreferences(context);
	}
	
	public boolean editKey (String key, boolean value)
	{
		SharedPreferences.Editor editor = preferences.edit();
		editor.putBoolean(key, value);
		
		return editor.commit();
	}
	
	public boolean editKey (String key, String value)
	{
		SharedPreferences.Editor editor = preferences.edit();
		editor.putString(key, value);
		
		return editor.commit();
	}
	
	public boolean editKey (String key, long value)
	{
		SharedPreferences.Editor editor = preferences.edit();
		editor.putLong(key, value);
		
		return editor.commit();
	}

	public SharedPreferences getSharedPreferences ()
	{
		return preferences;
	}
	
	public boolean deleteKey (String key)
	{
		SharedPreferences.Editor editor = preferences.edit();
		editor.remove(key);
		
		return editor.commit();
	}
	
	public boolean guardarDatos (Usuario usuario)
	{
		SharedPreferences.Editor editor = preferences.edit();
		
		editor.putLong(ID, usuario.getId());
		
		return editor.commit();
	}
	
	public boolean eliminarDatosUsuario ()
	{
		SharedPreferences.Editor editor = preferences.edit();
		
		editor.putLong(ID, 0);
		
		return editor.commit();
	}
	
	public long leerID ()
	{
		return preferences.getLong(ID, 0);
	}
	
	public boolean grabarID (long id)
	{
		SharedPreferences.Editor editor = preferences.edit();
		
		editor.putLong(ID, id);
		
		return editor.commit();
	}
}
